'use strict';

const moment = require('moment');

module.exports = app => {
  const { Sequelize } = app;

  const Addresses = app.model.define('Addresses', {
    id: {
      allowNull: false,
      autoIncrement: true,
      primaryKey: true,
      type: Sequelize.INTEGER
    },
    openId: {
      allowNull: false,
      type: Sequelize.STRING(100),
    },
    userId: {
      type: Sequelize.INTEGER(10),
      allowNull: false,
    },
    addressInfo: {
      type: Sequelize.JSON
    },
    createdAt: {
      allowNull: false,
      type: Sequelize.DATE,
      get() { return moment(this.getDataValue('createdAt')).format('YYYY-MM-DD HH:mm') }
    },
    updatedAt: {
      allowNull: false,
      type: Sequelize.DATE,
      get() { return moment(this.getDataValue('updatedAt')).format('YYYY-MM-DD HH:mm') }
    },
    deletedAt: {
      type: Sequelize.DATE,
    },
  }, {
    charset: 'utf8mb4',
    collate: 'utf8mb4_general_ci',
    indexes: [{
      fields: ['userId']
    }],
    comment: '地址表',
  });

  return Addresses;

};